package org.msss.gamebasic;

import org.lwjgl.util.Rectangle;
import org.newdawn.slick.opengl.Texture;

/**
 * Things like a tile or background would extend Icon.
 * 
 * @author alanxoc3
 * 
 */
public class Icon {
	
	public static final int DEFAULT_X = 0;
	public static final int DEFAULT_Y = 0;
	public static final int DEFAULT_W = 16;
	public static final int DEFAULT_H = 16;
	public static final int DEFAULT_Z = 0;

	// Some variables.
	private int z;
	private Rectangle bounds;
	private Texture image;

	public Icon(Texture image) {
		setImage(image);
		
		z = DEFAULT_Z;
	}

	/**
	 * Default Constructor.
	 */
	public Icon() {
		this(null);
	}

	/**
	 * Will be called in the game loop, contain's the code for drawing things
	 * such as pictures or shapes.
	 */
	public void draw() {
		Canvas.drawImageToRoom(image, getX(), getY(), getW(), getH(), getZ());
	}

	// Getters and setters...
	public int getX() {
		return bounds.getX();
	}

	public void setX(int x) {
		bounds.setX(x);
	}

	public int getY() {
		return bounds.getY();
	}

	public void setY(int y) {
		bounds.setY(y);
	}

	public int getW() {
		return bounds.getWidth();
	}

	public void setW(int w) {
		bounds.setWidth(w);
	}

	public int getH() {
		return bounds.getHeight();
	}

	public void setH(int h) {
		bounds.setHeight(h);
	}

	public int getZ() {
		return z;
	}

	public void setZ(int z) {
		this.z = z;
	}

	public Rectangle getBounds() {
		return bounds;
	}

	public void setBounds(Rectangle bounds) {
		this.bounds = bounds;
	}

	public Texture getImage() {
		return image;
	}

	public void setImage(Texture image) {
		this.image = image;
		
		if (image != null) {
			bounds = new Rectangle(DEFAULT_X, DEFAULT_Y, image.getImageWidth(), image.getImageHeight());
		} else {
			bounds = new Rectangle(DEFAULT_X, DEFAULT_Y, DEFAULT_W, DEFAULT_H);
		}
	}
}
